package com.loeng.module.infra.dal.mysql.logger;

import com.loeng.framework.common.pojo.PageResult;
import com.loeng.framework.mybatis.core.mapper.BaseMapperX;
import com.loeng.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.loeng.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import com.loeng.module.infra.dal.dataobject.logger.ApiAccessLogDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * API 访问日志 Mapper
 * @author loeng zhuo
 */
@Mapper
public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {

    default PageResult<ApiAccessLogDO> selectPage(ApiAccessLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApiAccessLogDO>()
                .eqIfPresent(ApiAccessLogDO::getTraceId, reqVO.getTraceId())
                .eqIfPresent(ApiAccessLogDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ApiAccessLogDO::getUserType, reqVO.getUserType())
                .likeIfPresent(ApiAccessLogDO::getApplicationName, reqVO.getApplicationName())
                .eqIfPresent(ApiAccessLogDO::getRequestMethod, reqVO.getRequestMethod())
                .eqIfPresent(ApiAccessLogDO::getRequestUrl, reqVO.getRequestUrl())
                .eqIfPresent(ApiAccessLogDO::getRequestParams, reqVO.getRequestParams())
                .eqIfPresent(ApiAccessLogDO::getResponseBody, reqVO.getResponseBody())
                .eqIfPresent(ApiAccessLogDO::getUserIp, reqVO.getUserIp())
                .eqIfPresent(ApiAccessLogDO::getUserAgent, reqVO.getUserAgent())
                .eqIfPresent(ApiAccessLogDO::getOperateModule, reqVO.getOperateModule())
                .likeIfPresent(ApiAccessLogDO::getOperateName, reqVO.getOperateName())
                .eqIfPresent(ApiAccessLogDO::getOperateType, reqVO.getOperateType())
                .betweenIfPresent(ApiAccessLogDO::getBeginTime, reqVO.getBeginTime())
                .betweenIfPresent(ApiAccessLogDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(ApiAccessLogDO::getDuration, reqVO.getDuration())
                .eqIfPresent(ApiAccessLogDO::getResultCode, reqVO.getResultCode())
                .eqIfPresent(ApiAccessLogDO::getResultMsg, reqVO.getResultMsg())
                .betweenIfPresent(ApiAccessLogDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ApiAccessLogDO::getId));
    }

}
